package querysrc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.subway.babynote.syncdata.*;


public class query_foods extends query {
	public query_foods(sqlConnectionHandler sqlconhandler)
	{
		super(sqlconhandler);
	}	
	
	public List<ClientDataRecordBase> get_foods(int ts)
	{
			
		ResultSet rs = null;
		querydb qdb = null;
		Connection con = null;
		ArrayList<ClientDataRecordBase> foods = new ArrayList<ClientDataRecordBase>();
		try
		{
			boolean bret = true;
			con = this.init();	
			qdb = new querydb(con,sqlscripts.sql_foods_sync);		
			bret = qdb.prePS();		
			if(bret)
			{
				//qdb.ps.setInt(1, ts);
				rs = qdb.execPSQuery();
				if(rs.next())
				{
					rs.beforeFirst();
					while(rs.next())
					{
						int id = rs.getInt(sqlscripts.sql_foods_sync_c1_food_id);
						int fpid = rs.getInt(sqlscripts.sql_foods_sync_c2_food_prop_id);
						String fn = rs.getString(sqlscripts.sql_foods_sync_c3_foodname);
						String unit = rs.getString(sqlscripts.sql_foods_sync_c4_unit);
						String category = rs.getString(sqlscripts.sql_foods_sync_c5_category);
						int t = rs.getInt(sqlscripts.sql_foods_sync_c6_ts);
						
						
						foods.add(new ClientDataRecord.foodsRecord(id,fpid,fn,unit,category,t));						
					}					
				}
			}			
			return foods;
		}
		catch(SQLException se) {
		      System.out.println("SQLException: "+se.getMessage());
		      return foods;
	    }
		catch(Exception e)
		{
			e.printStackTrace();
			return foods;
		}
		finally
		{
			this.release_resultset(rs);
			this.release_querydb(qdb);
			this.release_connection(con);
			this.finalize();
		}
	}
}
